﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {
    public float jumpHight = 4.0f;
    public bool isLanding = true;  // 是否着陆, 默认是

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (this.isLanding)
        {
            if (Input.GetMouseButtonDown(0))
            {
                this.isLanding = false;
                float y_speed = Mathf.Sqrt(2.0f * Mathf.Abs(Physics.gravity.y) * this.jumpHight);
                this.GetComponent<Rigidbody>().velocity = Vector3.up * y_speed;
            }
        }
	}

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Floor") {
            this.isLanding = true;
        }
    }
}
